package com.coai.message.dto

import com.coai.message.model.ConversationType
import com.coai.message.model.MessageType
import com.coai.message.model.ParticipantRole
import jakarta.validation.constraints.NotBlank
import jakarta.validation.constraints.NotEmpty
import jakarta.validation.constraints.Size
import java.time.LocalDateTime

// Conversation DTOs
data class ConversationDto(
    val id: String,
    val type: ConversationType,
    val name: String?,
    val avatar: String?,
    val lastMessage: LastMessageInfo?,
    val unreadCount: Int,
    val participants: List<ParticipantDto>,
    val createdAt: LocalDateTime
)

data class LastMessageInfo(
    val id: String,
    val content: String,
    val senderId: String,
    val senderName: String?,
    val messageType: MessageType,
    val createdAt: LocalDateTime
)

data class ParticipantDto(
    val userId: String,
    val username: String?,
    val avatar: String?,
    val role: ParticipantRole,
    val muted: Boolean,
    val pinned: Boolean
)

data class CreateConversationRequest(
    val type: ConversationType,
    
    @field:NotEmpty(message = "参与者不能为空")
    val participantIds: List<String>,
    
    val name: String? = null,
    val avatar: String? = null
)

data class UpdateConversationRequest(
    val name: String? = null,
    val avatar: String? = null
)

data class AddParticipantsRequest(
    @field:NotEmpty(message = "参与者不能为空")
    val userIds: List<String>
)

// Message DTOs
data class MessageDto(
    val id: String,
    val conversationId: String,
    val senderId: String,
    val senderName: String?,
    val senderAvatar: String?,
    val messageType: MessageType,
    val content: String,
    val metadata: Map<String, Any>?,
    val replyTo: ReplyMessageInfo?,
    val readBy: List<String>,
    val recalled: Boolean,
    val createdAt: LocalDateTime
)

data class ReplyMessageInfo(
    val id: String,
    val content: String,
    val senderId: String,
    val senderName: String?
)

data class SendMessageRequest(
    @field:NotBlank(message = "会话ID不能为空")
    val conversationId: String,
    
    val messageType: MessageType = MessageType.TEXT,
    
    @field:NotBlank(message = "消息内容不能为空")
    @field:Size(max = 10000, message = "消息内容不能超过10000字符")
    val content: String,
    
    val metadata: Map<String, Any>? = null,
    val replyToId: String? = null
)

data class MessageListResponse(
    val messages: List<MessageDto>,
    val hasMore: Boolean,
    val nextCursor: String?
)

data class MarkAsReadRequest(
    @field:NotEmpty(message = "消息ID不能为空")
    val messageIds: List<String>
)

// WebSocket DTOs
data class WebSocketMessage(
    val type: String,
    val data: Any,
    val timestamp: Long = System.currentTimeMillis()
)

data class MessageNotification(
    val action: String, // NEW_MESSAGE, MESSAGE_READ, MESSAGE_RECALLED
    val message: MessageDto?,
    val conversationId: String,
    val unreadCount: Int?
)

data class TypingNotification(
    val conversationId: String,
    val userId: String,
    val username: String,
    val isTyping: Boolean
)

data class OnlineStatusNotification(
    val userId: String,
    val status: String, // ONLINE, OFFLINE, BUSY, AWAY
    val lastSeen: LocalDateTime?
)
